//
//  SQLITE.h
//  VVVVVVVSQLIT3
//
//  Created by up72 on 13-7-29.
//  Copyright (c) 2013年 up72. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <sqlite3.h>

typedef NS_ENUM (NSInteger, OEDER)
{
    ASC, //正序,递增
    DESC //倒序,递减
};

@interface SQLITE : NSObject
{
    sqlite3 *database;
}

+ (id)standardSqlite;
- (int)counttable:(NSString *)table;
- (int)counttable:(NSString *)table key:(NSString *)key value:(NSString *)value;
- (NSMutableArray *)colKeyFromtable:(NSString *)table;
- (BOOL)openSqlite3;
- (BOOL)createTable:(NSString *)table forKey:(NSArray *)keyArray;
- (NSMutableArray *)selectDistinctWithKey:(NSString *)key table:(NSString *)table;
- (NSString *)sumWithKey:(NSString *)key form:(NSString *)table whereKey:(NSString *)whereKey whereValue:(NSString *)whereValue;
//--------------------------

- (BOOL)addSQLObject:(NSMutableDictionary *)anObject forKey:(NSString *)aKey;
- (BOOL)updateSQL:(NSString *)table WithKey:(NSString *)key fromValue:(NSString *)fromValue toValue:(NSString *)toValue;
- (BOOL)updateSQL:(NSString *)table WithKey:(NSString *)key andValue:(NSString *)value dict:(NSMutableDictionary *)dict;
- (NSMutableArray *)selectSQLFromtable:(NSString *)table
                            elementKey:(NSString *)keyWorld
                          elementValue:(NSString *)value
                                 order:(NSString *)orderKey
                                 limit:(NSInteger)limit
                                offset:(NSUInteger)offset
                                 order:(OEDER)order;
- (NSMutableArray *)selectSQLFromtable:(NSString *)table
                            elementKey:(NSString *)keyWorld
                          elementValue:(NSString *)value
                                 limit:(NSInteger)limit
                                offset:(NSUInteger)offset
                                 order:(OEDER)order;
- (BOOL)removeSQL:(NSString *)table withKey:(NSString *)aKey andValue:(NSString *)value;
- (BOOL)deleteSQLTable:(NSString *)table;
//--------------------------


#pragma mark - SQL 语句
- (BOOL)insertDataWithSQL:(NSString *)sql;
- (BOOL)deleteDataWithSQL:(NSString *)sql;
- (BOOL)updateDataWithSQL:(NSString *)sql;
- (NSMutableArray *)selectDataWithSQL:(NSString *)sql table:(NSString *)table;
@end
